<include file="Public:header" />
<div class="container">
	
	<div class="page-header">
		<h4>{:L('FINANCE')}<small> - <a href="{:U('finance/index','t=receivables')}">{:L('RECEIVABLES')}</a> | 
		<a class="active" href="{:U('finance/index','t=payables')}">{:L('PAYABLES')}</a> | 
		<a href="{:U('finance/index','t=receivingorder')}">{:L('RECEIVINGORDER')}</a> | 
		<a href="{:U('finance/index','t=paymentorder')}">{:L('PAYMENTORDER')}</a> | <a href="{:U('finance/analytics')}">{:L('STATISTICS')}</a></small> </h4>
	</div>
	<include file="Public:alert" />	
	<div class="row">
		<div class="span12">
			<form action="{:U('finance/add','t=payables')}" method="post">				
				<table class="table table-hover">
					<thead>
						<tr>
							<td>&nbsp;</td>
							<td><input name="submit" class="btn btn-primary" type="submit" value="{:L('SAVE')}"/> &nbsp; <if condition="C('ismobile') neq 1"><input name="submit" class="btn btn-primary" type="submit" value="{:L('SAVE AND NEW')}"/> &nbsp; </if><input class="btn" type="button" onclick="javascript:history.go(-1)" value="{:L('CANCEL')}"/></td>
						</tr>
					</thead>
					<tfoot>
						<tr>
							<td>&nbsp;</td>
							<td><input name="submit" class="btn btn-primary" type="submit" value="{:L('SAVE')}"/> &nbsp;  <if condition="C('ismobile') neq 1"><input name="submit" class="btn btn-primary" type="submit" value="{:L('SAVE AND NEW')}"/> &nbsp;</if> <input class="btn" type="button" onclick="javascript:history.go(-1)" value="{:L('CANCEL')}"/></td>
						</tr>
					</tfoot>
					<tbody>
						<tr>
							<th colspan="2">{:L('ADD PAYABLES')}</th>
						</tr>
						<tr>
							<td class="tdleft" width="20%" valign="middle">{:L('PAYABLES NAME')}</td>
							<td valign="middle"><input name="name" id="name" class="text-input large-input" type="text" /></td>
						</tr>
						<tr>
							<td class="tdleft" width="20%" valign="middle">{:L('CONTRACT')}</td>
							<td valign="middle"><input name="contract_id" id="contract_id" type="hidden" /><input name="contract_name" id="contract_name" class="text-input large-input" type="text" /></td>
						</tr>
						<tr>
							<td class="tdleft" width="20%" valign="middle">*{:L('CUSTOMER')}</td>
							<td valign="middle"><input name="customer_id" id="customer_id" type="hidden" /><input name="customer" id="customer" class="text-input large-input" type="text" /></td>
						</tr>
						<tr>
							<td class="tdleft" width="20%" valign="middle">{:L('OWNER_ROLE')}</td>
							<td valign="middle"><input name="owner_role_id" id="owner_role_id" type="hidden" value="{$Think.session.role_id}"/><input name="owner_name" id="owner_name" value="{$Think.session.name}" class="text-input large-input" type="text" /></td>
						</tr>
						<tr>
							<td class="tdleft" valign="middle">{:L('AMOUNT PAYABLE')}</td>
							<td valign="middle"><input class="text-input large-input" id="price" readonly="readonly" name="price" type="text" /></td>
						</tr>
						<tr>
							<td class="tdleft" valign="middle">{:L('PAYMENTORDER')}</td>
							<td valign="middle"> &nbsp; <input type="checkbox" name="check_add_order" id="check_add_order" value="1"/>&nbsp;{:L('WHILE CREATING PAYMENTORDER')}<br/>
								<table id="add_order" class="hide">
									<tr>
										<td class="tdleft" width="20%" valign="middle">{:L('PAYMENTS SINGLE NUMBER')}</td>
										<td valign="middle"><input name="order_name" class="text-input large-input" type="text" value="{:L('AUTOMATIC_GENERATION')}"/></td>
									</tr>
									<tr>
										<td class="tdleft" valign="middle">{:L('PAYMENTS')}</td>
										<td valign="middle"><input class="text-input large-input" placeholder="0.00" id="order_money" name="order_money" type="text" /></td>
									</tr>
									<tr>
										<td class="tdleft" valign="middle">{:L('PAYMENT TIME')}</td>
										<td valign="middle"><input onclick="WdatePicker()"  type="text" name="order_pay_time"/></td>
									</tr>
									<tr>
										<td class="tdleft" valign="middle">{:L('STATUS')}</td>
										<td valign="middle"><input  type="radio" checked="checked" name="order_status" value="0"/> {:L('NOT CLOSING')} <input type="radio"  name="order_status" value="1"/> {:L('HAS CLOSING')} </td>
									</tr>
									<tr>
										<td class="tdleft" valign="middle">{:L('DESCRIPTION')}</td>
										<td valign="middle"><textarea class="span4" rows="6" name="order_description"></textarea></td>
									</tr>
								</table>
							</td>
						</tr>
						<tr>
							<td class="tdleft" valign="middle">{:L('PAYABLES TIME')}</td>
							<td valign="middle"><input onclick="WdatePicker()"  type="text" id="pay_time" name="pay_time"/></td>
						</tr>
						<tr>
							<td class="tdleft" valign="middle">{:L('DESCRIPTION')}</td>
							<td valign="middle"><textarea class="span6" rows="6" name="description"></textarea></td>
						</tr>
					</tbody>
				</table>
			</form>
		</div> <!-- End #tab1 -->	
	</div> <!-- End #main-content -->	
</div>
<div id="dialog-message" title="{:L('SELECT THE CUSTOMERS')}">loading...</div>
<div id="dialog-message2" title="{:L('SELECT THE CONTRACT')}">loading...</div>
<div id="dialog-message3" title="{:L('SELECT THE LEADER')}">loading...</div>
<script type="text/javascript">
<if condition="C('ismobile') eq 1">width=$('.container').width() * 0.9;<else/>width=800;</if>
$("#dialog-message").dialog({
	autoOpen: false,
	modal: true,
	width: width,
	maxHeight: 400,
	buttons: {
		"Ok": function () {
			var item = $('input:radio[name="customer"]:checked').val();
			var name = $('input:radio[name="customer"]:checked').parent().next().html();
			if(item){
				$('#customer').val(name);
				$('#customer_id').val(item);
			}
			$(this).dialog("close");
		},
		"Cancel": function () {
			$(this).dialog("close");
		}
	},
	position: ["center", 100]
});
$("#dialog-message2").dialog({
	autoOpen: false,
	modal: true,
	width: width,
	maxHeight: 400,
	buttons: {
		"Ok": function () {
			var item = $('input:radio[name="contract"]:checked').val();
			var name = $('input:radio[name="contract"]:checked').parent().next().html();
			var next_item = $('input:radio[name="contract"]:checked').parent().next().next().html();
			var next_name = $('input:radio[name="contract"]:checked').parent().next().next().next().html();
			var price = $('input:radio[name="contract"]:checked').parent().nextAll().eq(3).html();
			if(item){
				$('#contract_name').val(name);
				$('#contract_id').val(item);
				$('#customer_id').val(next_item);
				$('#customer').val(next_name);
				$('#price').val(price);
			}
			$(this).dialog("close");
		},
		"Cancel": function () {
			$(this).dialog("close");
		}
	},
	position: ["center", 100]
});
$("#dialog-message3").dialog({
	autoOpen: false,
	modal: true,
	width: width,
	maxHeight: 400,
	buttons: {
		"Ok": function () {
			var item = $('input:radio[name="owner"]:checked').val();
			var name = $('input:radio[name="owner"]:checked').parent().next().html();
			if(item){
				$('#owner_name').val(name);
				$('#owner_role_id').val(item);
			}
			$(this).dialog("close");
		},
		"Cancel": function () {
			$(this).dialog("close");
		}
	},
	position: ["center", 100]
});
$(function(){
	$("input[name='submit']").click(function(){			
		if($("#name").val() == null || $("#name").val() == ""){
			alert('应收款名不能为空！');
			return false;
		}
	})
	$("#customer").click(
		function(){
			$('#dialog-message').dialog('open');
			$('#dialog-message').load('{:U("customer/listDialog","by=all&bid=".$_GET['bid'])}');
		}
	);
	$("#contract_name").click(
		function(){
			$('#dialog-message2').dialog('open');
			$('#dialog-message2').load('{:U("contract/listDialog","by=all&bid=".$_GET['bid'])}');
		}
	);
	$("#owner_name").click(
		function(){
			$('#dialog-message3').dialog('open');
			$('#dialog-message3').load('{:U("user/listDialog","by=all")}');
		}
	);
	$("#check_add_order").click(
		function(){
			is_checked = $(this).prop("checked");
			if(is_checked){
				$('#add_order').show();
			}else{
				$('#add_order').hide();
			}
		}
	);
});
$(document).ready(function(){
	$("#order_money").blur(function(){
		var total = parseFloat($('#price').val());
		var money =parseInt( parseFloat($('#order_money').val())*100 )/100;
		if( money > total){
			alert('{:L('PAYMENT_EXCEEDS_THE_AMOUNTS_PAYABLE')}');
		}
	});
});
</script>
<include file="Public:footer" />	